home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zvmem2.c < prev   
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.3 KB  |  156 lines

  1. /* Copyright (C) 1992, 1993, 1994, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zvmem2.c,v 1.2 2000/09/19 19:00:55 lpd Exp $ */
  20. /* Level 2 "Virtual memory" operators */
  21. #include "ghost.h"
  22. #include "oper.h"
  23. #include "estack.h"
  24. #include "ialloc.h"        /* for ivmspace.h */
  25. #include "ivmspace.h"
  26. #include "ivmem2.h"
  27. #include "store.h"
  28.  
  29. /* Garbage collector control parameters. */
  30. #define DEFAULT_VM_THRESHOLD_SMALL 20000
  31. #define DEFAULT_VM_THRESHOLD_LARGE 250000
  32. #define MIN_VM_THRESHOLD 1
  33. #define MAX_VM_THRESHOLD max_long
  34.  
  35. /* ------ Local/global VM control ------ */
  36.  
  37. /* <bool> .setglobal - */
  38. private int
  39. zsetglobal(i_ctx_t *i_ctx_p)
  40. {
  41.     os_ptr op = osp;
  42.     check_type(*op, t_boolean);
  43.     ialloc_set_space(idmemory,
  44.              (op->value.boolval ? avm_global : avm_local));
  45.     pop(1);
  46.     return 0;
  47. }
  48.  
  49. /* <bool> .currentglobal - */
  50. private int
  51. zcurrentglobal(i_ctx_t *i_ctx_p)
  52. {
  53.     os_ptr op = osp;
  54.  
  55.     push(1);
  56.     make_bool(op, ialloc_space(idmemory) != avm_local);
  57.     return 0;
  58. }
  59.  
  60. /* <any> gcheck/scheck <bool> */
  61. private int
  62. zgcheck(i_ctx_t *i_ctx_p)
  63. {
  64.     os_ptr op = osp;
  65.  
  66.     check_op(1);
  67.     make_bool(op, (r_is_local(op) ? false : true));
  68.     return 0;
  69. }
  70.  
  71. /* ------ Garbage collector control ------ */
  72.  
  73. /* These routines are exported for setuserparams. */
  74.  
  75. /*
  76.  * <int> setvmthreshold -
  77.  *
  78.  * This is implemented as a PostScript procedure that calls setuserparams.
  79.  */
  80. int
  81. set_vm_threshold(i_ctx_t *i_ctx_p, long val)
  82. {
  83.     gs_memory_gc_status_t stat;
  84.  
  85.     if (val < -1)
  86.     return_error(e_rangecheck);
  87.     else if (val == -1)
  88.     val = (gs_debug_c('.') ? DEFAULT_VM_THRESHOLD_SMALL :
  89.            DEFAULT_VM_THRESHOLD_LARGE);
  90.     else if (val < MIN_VM_THRESHOLD)
  91.     val = MIN_VM_THRESHOLD;
  92.     else if (val > MAX_VM_THRESHOLD)
  93.     val = MAX_VM_THRESHOLD;
  94.     gs_memory_gc_status(idmemory->space_global, &stat);
  95.     stat.vm_threshold = val;
  96.     gs_memory_set_gc_status(idmemory->space_global, &stat);
  97.     gs_memory_gc_status(idmemory->space_local, &stat);
  98.     stat.vm_threshold = val;
  99.     gs_memory_set_gc_status(idmemory->space_local, &stat);
  100.     return 0;
  101. }
  102.  
  103. /*
  104.  * <int> .vmreclaim -
  105.  *
  106.  * This implements only immediate garbage collection: enabling and
  107.  * disabling GC is implemented by calling setuserparams.
  108.  */
  109. int
  110. set_vm_reclaim(i_ctx_t *i_ctx_p, long val)
  111. {
  112.     if (val >= -2 && val <= 0) {
  113.     gs_memory_gc_status_t stat;
  114.  
  115.     gs_memory_gc_status(idmemory->space_system, &stat);
  116.     stat.enabled = val >= -1;
  117.     gs_memory_set_gc_status(idmemory->space_system, &stat);
  118.     gs_memory_gc_status(idmemory->space_global, &stat);
  119.     stat.enabled = val >= -1;
  120.     gs_memory_set_gc_status(idmemory->space_global, &stat);
  121.     gs_memory_gc_status(idmemory->space_local, &stat);
  122.     stat.enabled = val == 0;
  123.     gs_memory_set_gc_status(idmemory->space_local, &stat);
  124.     return 0;
  125.     } else
  126.     return_error(e_rangecheck);
  127. }
  128. private int
  129. zvmreclaim(i_ctx_t *i_ctx_p)
  130. {
  131.     os_ptr op = osp;
  132.  
  133.     check_type(*op, t_integer);
  134.     if (op->value.intval == 1 || op->value.intval == 2) {
  135.     /* Force the interpreter to store its state and exit. */
  136.     /* The interpreter's caller will do the actual GC. */
  137.     return_error(e_VMreclaim);
  138.     }
  139.     return_error(e_rangecheck);
  140. }
  141.  
  142. /* ------ Initialization procedure ------ */
  143.  
  144. /* The VM operators are defined even if the initial language level is 1, */
  145. /* because we need them during initialization. */
  146. const op_def zvmem2_op_defs[] =
  147. {
  148.     {"0.currentglobal", zcurrentglobal},
  149.     {"1.gcheck", zgcheck},
  150.     {"1.setglobal", zsetglobal},
  151.         /* The rest of the operators are defined only in Level 2. */
  152.     op_def_begin_level2(),
  153.     {"1.vmreclaim", zvmreclaim},
  154.     op_def_end(0)
  155. };
  156.